﻿@{
    ViewBag.Title = "角色管理";
    Layout = "~/Views/Shared/_Index.cshtml";
}
    <div class="wrapper wrapper-content  animated fadeInRight">
        <div class="ibox">
            <div class="ibox-content">
                <div id="toolbar" class="btn-group">
                </div>
                <div>
                    <table id="roleTable"></table>
                </div>
            </div>
          
        </div>
    </div>
@section scripts
{
    <script>
        var $roleTable;
        $(function() {
            loadGrid();
        });

        function loadGrid() {
            $roleTable = $("#roleTable").bootstrapTable({
                url: '/admin/sysrole/GetData',
                toolbar: '#toolbar',
                pagination: true,
                height: $(window).height() - 50,
                pageSize: 15,
                pageList: [5, 10, 15, 20],
                showColumns: true,
                showRefresh: true,
                clickToSelect: true,
                sidePagination: "server",
                locale: "zh-CN",
                striped: true,
                uniqueId:'id',
                columns: [
                    { field: 'ck', checkbox: true },
                    { field: 'role_name', title: '角色名称', align: 'center' },
                    { field: 'role_code', title: '角色编码', align: 'center' },
                    { field: 'sort', title: '排序', align: 'center' },
                    { field: 'remark', title: '备注', align: 'center' },
                    {
                        field: 'role_super',
                        title: '是否超级管理员',
                        align: 'center',
                        formatter: function(value, row, index) {
                            if (value) {
                                return '是';
                            } else {
                                return '否';
                            }
                        }
                    },
                    { field: 'id', title: '操作', align: 'center', formatter: renderOpts}
                ]

            });

            jutils.initToolBarRole('#toolbar', true);
        }

        function renderOpts(v, d, i) {
            return jutils.initToolBarRow(v);
        }

        function add() {
            jutils.dialogForm('角色信息', '/admin/sysrole/form/', {id:''},
                function() {
                    $roleTable.bootstrapTable('refresh');
                });
        }

        function edit(obj) {

            var id = $(obj).data('id');
            jutils.dialogForm('角色信息', '/admin/sysrole/form', { id: id},
                function () {
                    $roleTable.bootstrapTable('refresh');
                });
        }

        function del(obj) {
            var id = $(obj).data('id');


            jutils.confirm('确认删除吗',
                function() {
                    jutils.ajaxGet('/admin/sysrole/DelRoleByIds',
                        { ids: id},
                        function() {
                            $roleTable.bootstrapTable('refresh');
                        });
                });
        }

        function setrole(obj) {

            var id = $(obj).data('id');
            var row = $roleTable.bootstrapTable('getRowByUniqueId', id);//行的数据
            var name = row.role_name;
           
            jutils.dialogForm('角色权限信息', '/admin/sysrole/SetRoleAuthNew', { id:id,roleName:name},
                function() {
                    $roleTable.bootstrapTable('refresh');
                });
        }
        
    </script>


}